home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_11_05 / test_obj / tutils.h < prev   
C/C++ Source or Header  |  1993-01-20  |  4KB  |  78 lines

  1. /* File:     tutils.h
  2.    Copyright Norman Wilde 1993
  3.    Notes:    Header for utility functions for building test drivers.
  4.          In general, the generated "test driver" is a c++ file (stdout)
  5.          created from a test file (stdin). The test driver consists of:
  6.            - "embedded blocks" copied from the test file
  7.            - function definitions, one to set
  8.                each variable in each input "runtest" statement plus
  9.                a bottom level function to call the code being tested.
  10.            - a main program that calls the top function from
  11.                each runtest statement.
  12.          When compiled and executed, the test driver will cycle thru
  13.          one set of tests for each runtest statement.
  14. */
  15. /* ----------- buffer for strings, blocks, etc. ------------- */
  16.   void collect(char c);             /* collect char c into the buffer */
  17.   void collectFirst(char c);        /* reset buf and collect c */
  18.   char * release();                 /* copy the string in the buf to the 
  19.                                     /* heap, terminate, and return the copy.*/
  20. /* ----------- simple linked list of strings with data---------------- */
  21.   struct STRLIST {
  22.     char * str;
  23.     void * data;
  24.     struct STRLIST * next;
  25.     };
  26.   struct STRLIST * listNew(char* aStr, void * aData);
  27.     /* Answer a new list with aStr as only element */
  28.   struct STRLIST * listAdd(struct STRLIST * aList,char* aStr, void * aData);
  29.     /* Add aStr to aList */
  30.   void * listFind(struct STRLIST * aList, char * aStr);
  31.     /* Locate string matching aStr in aList. Answer the data ptr. if
  32.        found, NULL if not found */
  33.   int listSize(struct STRLIST *aList);
  34.     /* Answer the number of elements in the list */
  35.  
  36. /* --- routines to create the test driver program ------- */
  37.   void addBlock(char * block);
  38.    /* add to the driver the given embedded block */
  39.   void setRunName(char * theRName);
  40.    /* set the name of the test run to the first 20 chars of theRName*/
  41.   void makeVary(struct STRLIST * varList, char * block);
  42.    /* add to the driver the code for a "runtest ... varying ..." stmt. */
  43.   void makeComb(struct STRLIST * varList, char * block);
  44.    /* add to the driver the code for a "runtest ... combining ..." stmt. */
  45.   void writeDriver(void);
  46.    /* write the main function of the driver to standard output */
  47.  
  48. /* --- routines to manage a table of all the variables in a test file --- */
  49.   struct VARIABLE {         /* each variable has a set of values */
  50.     char * name;            /* string with name of the variable */
  51.     char * dtype;           /* string with type for use in declarations */
  52.     char * atype;           /* string with type for use in argument list */
  53.     struct STRLIST * inits; /* list of initializers, one for each
  54.                                      of the values of the variable */
  55.   };
  56.   void addVars(struct STRLIST * vList, char * typeStr, struct STRLIST * iList);
  57.     /* Add to the table the variables in vList, each of which is
  58.        of type typeStr (both for declarations and arguments)
  59.        and has the set of initializors iList */
  60.     /* NOTE - addVars is obsolete - should use addTVars that allows user
  61.        to control if objects are passed by value or by reference */
  62.   void addTVars(struct STRLIST * vList, char * decType, char * argType, struct STRLIST * iList);
  63.     /* Add to the table the variables in vList, each of which is
  64.        of type decType for declarations and type argType for arguments
  65.        and has the set of initializors iList */
  66.   char * getVarDecType(char * aVar);
  67.     /* answer a string with the type of the variable, suitable for
  68.        a C/C++ declaration */
  69.   char * getVarArgType(char * aVar);
  70.     /* answer a string with the type of the variable, suitable for
  71.        a C/C++ function argument declaration */
  72.   int getVarNumVals(char * aVar);
  73.     /* answer the number of values in the set of initializors of
  74.        aVar, or 0 if aVar is not found in the table */
  75.   char * getVarDeclStr(char * aVar);
  76.     /* answer a string with a c/c++ initialized declaration for
  77.        aVar, using all the initializors of the variable */
  78.